package com.dragon.logical.service.contract.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dragon.repository.entity.OtherFile;
import com.dragon.repository.mapper.OtherFileMapper;
import com.dragon.logical.service.contract.IOtherFileService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sy
 * @since 2023-07-06
 */
@Service
public class OtherFileServiceImpl extends ServiceImpl<OtherFileMapper, OtherFile> implements IOtherFileService {

    @Autowired
    OtherFileMapper mapper;


    @Override
    public void addFile(OtherFile convert) {

        mapper.insert(convert);
    }

    @Override
    public void updateFile(OtherFile file){
        //删除之前的
        List<OtherFile> otherFiles = mapper.selectList(new QueryWrapper<OtherFile>().lambda().eq(OtherFile::getCorrelationId, file.getCorrelationId())
                .eq(OtherFile::getStreamType, file.getStreamType()));
        for (OtherFile otherFile : otherFiles) {
            mapper.deleteById(otherFile);
        }
        mapper.insert(file);
    }

    @Override
    public void deleteFile(Integer id){
        List<OtherFile> otherFiles = mapper.selectList(new QueryWrapper<OtherFile>().lambda().eq(OtherFile::getCorrelationId, id));
        for (OtherFile otherFile : otherFiles) {
            mapper.deleteById(otherFile);
        }
    }

    @Override
    public List<OtherFile> fileList(Integer correlationId,  Integer streamType) {
        List<OtherFile> list = mapper.selectList(new QueryWrapper<OtherFile>().lambda().eq(OtherFile::getCorrelationId, correlationId)
                .eq(OtherFile::getStreamType, streamType));
        return list;
    }

}
